package com.hmkj.web.controller.my;

import com.hmkj.common.entity.ResultEntity;
import com.hmkj.common.page.BasePageParams;
import com.hmkj.common.page.Pages;
import com.hmkj.core.mapper.amount.AccountLogMapper;
import com.hmkj.core.po.amount.AccountLog;
import com.hmkj.core.po.amount.Cash;
import com.hmkj.core.po.user.User;
import com.hmkj.core.service.amount.AccountLogService;
import com.hmkj.core.service.amount.CashService;
import com.hmkj.core.service.amount.RechargeService;
import com.hmkj.web.controller.GenericController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * ......................我佛慈悲......................
 * ......................_oo0oo_.......................
 * .....................o8888888o......................
 * .....................88" . "88......................
 * .....................(| -_- |)......................
 * .....................0\  =  /0......................
 * ...................___/`---'\___....................
 * ..................' \\|     |// '...................
 * ................/ \\|||  :  |||// \.................
 * .............../ _||||| -卍-|||||- \................
 * ..............|   | \\\  -  /// |   |...............
 * ..............| \_|  ''\---/''  |_/ |...............
 * ..............\  .-\__  '-'  ___/-. /...............
 * ............___'. .'  /--.--\  `. .'___.............
 * .........."" '<  `.___\_<|>_/___.' >' ""............
 * ........| | :  `- \`.;`\ _ /`;.`/ - ` : | |.........
 * ........\  \ `_.   \_ __\ /__ _/   .-` /  /.........
 * ....=====`-.____`.___ \_____/___.-`___.-'=====......
 * ......................`=---='.......................
 * ....................................................
 * .................佛祖开光 ,永无BUG...................
 */
@Api(description = "资金明细相关")
@Slf4j
@RestController
@RequestMapping(GenericController.MEMBER_URL + "/fund")
public class MyFundDetailController extends GenericController<Integer, Cash> {
    @Resource
    private CashService cashService;
    @Resource
    private RechargeService rechargeService;
    @Resource
    private AccountLogService accountLogService;
//
//    @ApiOperation(value = "个人中心-资金明细-提现记录", notes = "提现记录")
//    @ResponseBody
//    @RequestMapping(value = "cash", method = RequestMethod.POST)
//    public ResultEntity<Pages<Cash>> cashList(@ApiParam("类型") @RequestParam(required = false) Integer type,
//                                              @ModelAttribute BasePageParams basePageParams) {
//        User user = getLoginUser();
//        Map<String, Object> param = new HashMap<>();
//        param.put("type", type);
//        param.put("userId", user.getId());
//        param.put("basePageParams", basePageParams);
//        Pages<Cash> pages = cashService.selectByPage(basePageParams,
//                q -> ((CashMapper) q).findCountForCashList(param),
//                q -> ((CashMapper) q).findListForCashList(param));
//        return ok(pages);
//    }
//
//    @ApiOperation(value = "个人中心-资金明细-充值记录", notes = "充值记录")
//    @ResponseBody
//    @RequestMapping(value = "recharge", method = RequestMethod.POST)
//    public ResultEntity<Pages<Recharge>> rechargeList(@ApiParam("类型") @RequestParam(required = false) Integer type,
//                                                      @ModelAttribute BasePageParams basePageParams) {
//
//        User user = getLoginUser();
//        Map<String, Object> param = new HashMap<>();
//        param.put("type", type);
//        param.put("userId", user.getId());
//        param.put("basePageParams", basePageParams);
//        Pages<Recharge> pages = rechargeService.selectByPage(basePageParams,
//                q -> ((RechargeMapper) q).findCountForRechargeList(param),
//                q -> ((RechargeMapper) q).findListForRechargeList(param));
//        return ok(pages);
//    }


    @ApiOperation(value = "个人中心-资金明细-资金记录", notes = "资金记录")
    @ResponseBody
    @RequestMapping(value = "log", method = RequestMethod.POST)
    public ResultEntity<Pages<AccountLog>> accountLogList(@ApiParam("类型 1充值 2提现 0/null全部") @RequestParam(required = false) Integer type,@ApiParam("开始时间") @RequestParam(required = false) String startTime,
                                                          @ApiParam("结束时间") @RequestParam(required = false) String endTime, @ModelAttribute BasePageParams basePageParams) {
        User user = getLoginUser();
        Map<String, Object> param = new HashMap<>();
        param.put("type", type == null ? null : type.equals(0) ? null : type);
        if(startTime==null || startTime.equals("")){
            startTime = "";
        }
        param.put("startTime",startTime);
        if(endTime  == null || endTime.equals("")){
            endTime = "";
        }
        param.put("endTime",endTime);
        param.put("userId", user.getId());
        param.put("basePageParams", basePageParams);
        Pages<AccountLog> pages = accountLogService.selectByPage(basePageParams,
                q -> ((AccountLogMapper) q).findCountForAccountLogList(param),
                q -> ((AccountLogMapper) q).findListForAccountLogList(param));
        return ok(pages);
    }
}
